package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.RightsMapper;
import com.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RightsServiceImpl implements RightsService{
    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> list() {
        return rightsMapper.selectList(null);
    }

    /**
     * 查询一级列表信息 条件parent_id=0
     * 查询一级目录下的二级列表信息  条件 parent_id=1
     * @return
     */
    @Override
    public List<Rights> getRightList() {
        QueryWrapper<Rights> queryWrapper= new QueryWrapper();
        queryWrapper.eq("parent_Id",0);
       List<Rights> list=rightsMapper.selectList(queryWrapper);
       for(Rights rights:list){
//           遍历list集合+数据
//           queryWrapper.clear();//清空以前的条件构造器
           QueryWrapper queryWrapper1=new QueryWrapper();
           queryWrapper1.eq("parent_Id",rights.getId());
//           根据一级的ID,查询子级信息
           List<Rights> children = rightsMapper.selectList(queryWrapper1);
//          将对象进行封装
           rights.setChildren(children);
       }
        return list;
    }
}
